#from django.template import Context, loader
from models import Poll
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response, get_object_or_404

from betterspace.courses.models import Course

def index(request):
    c = request.course
    latest_poll_list = Poll.objects.filter(course=c).order_by('-pub_date')[:5]
    return render_to_response('courses/polls/index.html',
        {'latest_poll_list': latest_poll_list,'course':c})
    
def detail(request, poll_id):
    p = get_object_or_404(Poll,pk=poll_id)
    return render_to_response('polls/detail.html', {'poll': p})
    #return HttpResponse("You're looking at poll %s." % poll_id)

def results(request, poll_id):
    return HttpResponse("You're looking the results of poll %s." % poll_id)

def vote(request, poll_id):
    """
    This is the view for voting on a poll!  Yay!  And you're reading
    its docstring!
    
    @required_level: student
    """
    return HttpResponse("You're voting on poll %s." % poll_id)
